package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"video/models"
)

type VideoController struct {
	beego.Controller
}

func (c *VideoController) Add() {

	title := c.GetString("title")
	profile := c.GetString("profile")
	img := c.GetString("img")
	times := c.GetString("times")
	user := c.GetString("user")

	var video = models.Video{
		Title:   title,
		Profile: profile,
		Img:     img,
		Times:   times,
		User:    user,
	}
	err := models.DB.Create(&video).Error
	if err != nil {
		c.Data["json"] = models.JsonR{
			Code: 0,
			Msg:  "添加失败",
			Data: nil,
		}
		c.ServeJSON()
		return
	}
	c.Data["json"] = models.JsonR{
		Code: 200,
		Msg:  "添加成功",
		Data: nil,
	}
	c.ServeJSON()
}
